package cn.openea.perpartner.meily.coupon.controller;

import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.meily.coupon.entity.Coupon;
import cn.openea.perpartner.meily.coupon.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author rains
 * @since 2023-06-16 11:28
 */
@Api(tags = "平台优惠券")
@RestController
@RequestMapping("coupon")
public class CouponController extends BaseController {
    @Resource
    private ICouponService couponService;

    @ApiOperation(value = "发放优惠券", notes = "创建并发放优惠券给用户")
    @PostMapping("/issue")
    public AjaxResult issueCoupons(@RequestBody @Valid Coupon coupon){
        if(!couponService.issueCoupons(coupon)){
            return AjaxResult.error("发放失败！");
        }
        return AjaxResult.success("发放成功！");
    }
}
